import java.text.SimpleDateFormat

import org.apache.spark.{SparkConf, SparkContext}
import org.slf4j.LoggerFactory
import com.google.gson._
import java.util.Date

import scala.collection.mutable.ArrayBuffer
import scala.xml._

/**
  * Created by THINKPAD on 2017/9/28.
  */
object tanzhen {
  val log= LoggerFactory.getLogger(tanzhen.getClass)

  def main(args: Array[String]) {
    val destOutName = "xiHai10"

    val conf =new SparkConf().setAppName(s"tanzhen-" + destOutName)
      .setMaster("local[8]")
      .setJars(List("C:\\Codes\\IdeaProjects\\MachineLearning\\JiQiXueXi\\outJar\\JiQiXueXi.jar"))
    conf.set("spark.serializer","org.apache.spark.serializer.KryoSerializer")
    val sc=new SparkContext(conf)

    log.info("-----------------------Start Spark Context-----------------------" +destOutName)
    val text = sc.textFile("D:\\data\\探针\\sample")
    val test = new JsonParser().parse(text.first()).getAsJsonObject
    val data = test.get("data")
    val data1 = data.getAsJsonArray
    val data2 = data1.get(1).getAsJsonObject
    if (data2.get("router1") == null){
      println("It is Null!!!")
    }

    for (i<- 0 until data1.size()){
      println(data1.get(i))
    }
    val Time2 = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss")
    val time = test.get("time").toString  .replace("\"","")
    val time2 = new Date(time)
  println(time2)
    val time3 = Time2.format(time2)
    println(time3)
    println(time2.getTime())
   println( Time2.parse(time3))
//两个日期相差天数
    (Time2.parse("10-09").getTime -  Time2.parse("10-01").getTime)/(1000*3600*24)
    println("-------------------------------------------------")
    val someXML = XML.loadFile("D:\\data\\探针\\sample2\\SCH-XiHaiNo10-170926_08_Flow.xml")
//    println(someXML)
    val realMacList = someXML\"RealMacList"
//    println(realMacList)
    val try1 = realMacList(0).child.toArray

//    println(try1(0))

    val MuUV = someXML\"MuUV"
    val realUV = MuUV.filter(_\"@FakeMac" == "0")
    val realUV1 = MuUV.filter(f=>f.child\"@FakeMac" == "0")
    println(realUV)

    val try2 = MuUV.map(f=>{
      val arr = new ArrayBuffer[String]()
      for (node<- f.child){
        val arrS = new ArrayBuffer[String]()
        if (node.attribute("FakeMac").get.toString() == "0"){
          val MuName = node.label.toString.split("_")(1)
          val times = node.child.map(f=>f.attribute("UTime").getOrElse("null").toString).toArray


        }
      }
      arr.toArray
    })

    val try3 = MuUV.map(f=>{
      val arr = new ArrayBuffer[String]()
      for (node<- f.child){
        val arrS = new ArrayBuffer[String]()
        if (node.attribute("FakeMac").getOrElse("111").toString() == "0"){
          val MuName = node.label.toString.split("_")(1)
          val times = node.child.map(f=>f.attribute("UTime").getOrElse("null").toString).toArray
          arr += times.mkString("\t")
        }
      }
      arr.toArray
    })



  }

}
